{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---------\n",
    "\n",
    "* 本学习记录人：许智超    \n",
    "* 学习时间：2021-11-11   \n",
    "* week06   \n",
    "* [参考的文档](https://python.org/doc)\n",
    "* [许老师博客](https://cnblogs.com/xuzhichao)\n",
    "\n",
    "---------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 本周学习内容\n",
    "\n",
    "\n",
    "## 1. 认识[列表](https://docs.python.org/3/tutorial/introduction.html#lists)\n",
    "\n",
    "\n",
    "\n",
    "## 2. 列表的取值\n",
    "\n",
    "## 3. 列表的一般方法\n",
    "\n",
    "## 4. 列表的高级方法"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.1 初始列表\n",
    "\n",
    "> 1. 列表的样式： [元素1,元素2,元素3,...]\n",
    "> 2. 列表的性质:\n",
    ">> 1. 列表是有顺序的（Sequence Types 序列类型的数据），第一个元素的位置/索引（index）是 0\n",
    ">> 2. 列表可以存放不同的类型数据， **但是** 一般存放相同类型数据\n",
    ">> 3. 列表可以按照序列数据 进行 取值（index） & 切片（slices）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "username_database = \"Alex;Jack;zhichao;Marry\"\n",
    "username_database_list = [\"Alex\",\"Jack\",\"zhichao\",\"Marry\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jack\n",
      "Jack\n"
     ]
    }
   ],
   "source": [
    "# 目标取出每一个账号名称\n",
    "print(username_database[5:9]) #字符串就显得比较麻烦\n",
    "print(username_database_list[1]) # 列表可以按照独立元素进行取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "#列表中可以包含不同的 types （int\\float\\str..也可是列表）数据 * 不常这样用\n",
    "different_types_list = [\"Alex\",18,175.5,[\"广东省广州市广州南方学院\",510970]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Alex'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "different_types_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "18"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "different_types_list[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "175.5"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "different_types_list[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['广东省广州市广州南方学院', 510970]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "different_types_list[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "510970"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "different_types_list[3][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思考： 取值是否需要知道列表的长度？如果列表只有5个元素，\n",
    "# 取值不能取5以上\n",
    "squares = [1, 4, 9, 16, 25]\n",
    "print(squares[0])\n",
    "#print(squares[10]) # IndexError（索引错误）: list index out of range\n",
    "# 一般 列表的取值需要先知道/清楚列表的长度，取值不要超过其长度范围\n",
    "len(squares) # 取值 不应大于 长度5 位置4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.1 切片 （slices）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares=[1, 4, 9, 16, 25]\n",
    "squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 16]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# （从左往右取） 9和16：\n",
    "squares[2:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 16]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# （从右往左取）9和16\n",
    "squares[-3:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 16, 25]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# （从左往右取） 9，16，25：结论：取到末尾或者首位都一律不写最好\n",
    "squares[2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 16, 25]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# （从右往左取） 9，16，25：\n",
    "squares[-3:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 9]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取1,9？,回顾切片的步长step  [start,stop,step]\n",
    "squares[:3:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
